package com.team2.outpatient_sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.team2.outpatient_sys.dao.DispenseDao;
import com.team2.outpatient_sys.pojo.Dispense;
import com.team2.outpatient_sys.pojo.Medicine;
import com.team2.outpatient_sys.service.DispenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class DispenseServiceImpl implements DispenseService {

    @Autowired
    private DispenseDao dispenseDao;


    @Override
    public boolean add(Dispense dispense) {
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String time = simpleDateFormat.format(new Date());
        dispense.setDispenseTime(time);
        return dispenseDao.add(dispense) > 1 ? false : true;
    }

    @Override
    public boolean delete(Integer id) {
        return dispenseDao.delete(id) > 1 ? false : true;
    }

    @Override
    public boolean update(Dispense dispense) {
        return dispenseDao.update(dispense) > 1 ? false : true;
    }

    @Override
    public List<Dispense> findAll() {
        return dispenseDao.findAll();
    }

    @Override
    public Dispense findById(Integer id) {
        return dispenseDao.findById(id);
    }

    @Override
    public List<Medicine> findDispense(Integer prescriptionId) {
        List<Medicine> list = dispenseDao.findDispense(prescriptionId);
        return list;
    }

//    @Override
//    public List<Medicine> findByPage(Integer currentPage, Integer pageSize) {
//        PageHelper.startPage(currentPage,pageSize);
//        List<Medicine> list=dispenseDao.findDispense();
//        return list;
//    }
}
